//
//  UserModel.swift
//
//  Created by eme on 2016/12/1
//  Copyright (c) . All rights reserved.
//

import Foundation
import SwiftyJSON
import RealmSwift
import ModelProtocol

public class UserModel:Object , ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kUserIdentityplaceKey: String = "identityplace"
    internal let kUserOrganKey: String = "organ"
    internal let kUserQqnameKey: String = "qqname"
    internal let kUserDevidKey: String = "devid"
    internal let kUserAppnameKey: String = "appname"
    internal let kUserAppidKey: String = "appid"
    internal let kUserUsertypeKey: String = "usertype"
    internal let kUserWeiboKey: String = "weibo"
    internal let kUserIdentitynoKey: String = "identityno"
    internal let kUserNicknameKey: String = "nickname"
    internal let kUserUseridKey: String = "userid"
    internal let kUserQqKey: String = "qq"
    internal let kUserUsersitenameKey: String = "usersitename"
    internal let kUserPhoneKey: String = "phone"
    internal let kUserWechatnameKey: String = "wechatname"
    internal let kUserRealnameKey: String = "realname"
    internal let kUserWechatKey: String = "wechat"
    internal let kUserUserfaceKey: String = "userface"
    internal let kUserThrStateKey: String = "thrState"
    internal let kUserWeibonameKey: String = "weiboname"
    internal let kUserEmailKey: String = "email"
    internal let kUserRegtimeKey: String = "regtime"
    internal let kUserUseraddressKey: String = "useraddress"
    internal let kUserUsernameKey: String = "username"
    internal let kUserBirthdayKey: String = "birthday"
    internal let kUserNationKey: String = "nation"
    internal let kUserThridKey: String = "thrid"
    internal let kUserSexKey: String = "sex"
    
    
    // MARK: 属性
    public  dynamic  var identityplace: String!
    public  dynamic  var organ: String!
    public  dynamic  var qqname: String!
    public  dynamic  var devid: String!
    public  dynamic  var appname: String!
    public  dynamic  var appid: Int = 0
    public  dynamic  var usertype: String!
    public  dynamic  var weibo: String!
    public  dynamic  var identityno: String!
    public  dynamic  var nickname: String!
    public  dynamic  var userid: String!
    public  dynamic  var qq: String!
    public  dynamic  var usersitename: String!
    public  dynamic  var phone: String!
    public  dynamic  var wechatname: String!
    public  dynamic  var realname: String!
    public  dynamic  var wechat: String!
    public  dynamic  var userface: String!
    public  dynamic  var thrState: String!
    public  dynamic  var weiboname: String!
    public  dynamic  var email: String!
    public  dynamic  var regtime: String!
    public  dynamic  var useraddress: String!
    public  dynamic  var username: String!
    public  dynamic  var birthday: String!
    public  dynamic  var nation: String!
    public  dynamic  var thrid: String!
    public  dynamic  var sex: String!
    public  dynamic  var agmobile: String!
    public  dynamic  var agtelphone: String!
    //代理联系人
    public  dynamic  var agcontact: String!
    ///代理名称
    public  dynamic  var agname: String!
    ///代理名称
    public  dynamic  var agmail: String!
    
    
    
    
    
    public  dynamic var glShop:GlShopModel!
    
    public override  static func primaryKey() -> String? {
        return "userid"
    }
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    public required  convenience  init?(json: JSON) {
        self.init()
        identityplace = json[kUserIdentityplaceKey].stringValue
        organ = json[kUserOrganKey].stringValue
        qqname = json[kUserQqnameKey].stringValue
        devid = json[kUserDevidKey].stringValue
        appname = json[kUserAppnameKey].stringValue
        appid = json[kUserAppidKey].intValue
        usertype = json[kUserUsertypeKey].stringValue
        weibo = json[kUserWeiboKey].stringValue
        identityno = json[kUserIdentitynoKey].stringValue
        nickname = json[kUserNicknameKey].stringValue
        userid = json[kUserUseridKey].stringValue
        qq = json[kUserQqKey].stringValue
        usersitename = json[kUserUsersitenameKey].stringValue
        phone = json[kUserPhoneKey].stringValue
        wechatname = json[kUserWechatnameKey].stringValue
        realname = json[kUserRealnameKey].stringValue
        wechat = json[kUserWechatKey].stringValue
        userface = json[kUserUserfaceKey].stringValue
        thrState = json[kUserThrStateKey].stringValue
        weiboname = json[kUserWeibonameKey].stringValue
        email = json[kUserEmailKey].stringValue
        regtime = json[kUserRegtimeKey].stringValue
        useraddress = json[kUserUseraddressKey].stringValue
        username = json[kUserUsernameKey].stringValue
        birthday = json[kUserBirthdayKey].stringValue
        nation = json[kUserNationKey].stringValue
        thrid = json[kUserThridKey].stringValue
        sex = json[kUserSexKey].stringValue
        agmobile = json["agmobile"].stringValue
        agtelphone = json["agtelphone"].stringValue
        agmail = json["agmail"].stringValue
        agcontact = json["agcontact"].stringValue
        agname = json["agname"].stringValue
        glShop = GlShopModel(json: json["glShop"])
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    public func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        if identityplace != nil {
            dictionary.updateValue(identityplace! as AnyObject, forKey: kUserIdentityplaceKey)
        }
        if organ != nil {
            dictionary.updateValue(organ! as AnyObject, forKey: kUserOrganKey)
        }
        if qqname != nil {
            dictionary.updateValue(qqname! as AnyObject, forKey: kUserQqnameKey)
        }
        if devid != nil {
            dictionary.updateValue(devid! as AnyObject, forKey: kUserDevidKey)
        }
        if appname != nil {
            dictionary.updateValue(appname! as AnyObject, forKey: kUserAppnameKey)
        }
        dictionary.updateValue(appid as AnyObject, forKey: kUserAppidKey)
        if usertype != nil {
            dictionary.updateValue(usertype! as AnyObject, forKey: kUserUsertypeKey)
        }
        if weibo != nil {
            dictionary.updateValue(weibo! as AnyObject, forKey: kUserWeiboKey)
        }
        if identityno != nil {
            dictionary.updateValue(identityno! as AnyObject, forKey: kUserIdentitynoKey)
        }
        if nickname != nil {
            dictionary.updateValue(nickname! as AnyObject, forKey: kUserNicknameKey)
        }
        dictionary.updateValue(userid as AnyObject, forKey: kUserUseridKey)
        if qq != nil {
            dictionary.updateValue(qq! as AnyObject, forKey: kUserQqKey)
        }
        if usersitename != nil {
            dictionary.updateValue(usersitename! as AnyObject, forKey: kUserUsersitenameKey)
        }
        if phone != nil {
            dictionary.updateValue(phone! as AnyObject, forKey: kUserPhoneKey)
        }
        if wechatname != nil {
            dictionary.updateValue(wechatname! as AnyObject, forKey: kUserWechatnameKey)
        }
        if realname != nil {
            dictionary.updateValue(realname! as AnyObject, forKey: kUserRealnameKey)
        }
        if wechat != nil {
            dictionary.updateValue(wechat! as AnyObject, forKey: kUserWechatKey)
        }
        if userface != nil {
            dictionary.updateValue(userface! as AnyObject, forKey: kUserUserfaceKey)
        }
        if thrState != nil {
            dictionary.updateValue(thrState! as AnyObject, forKey: kUserThrStateKey)
        }
        if weiboname != nil {
            dictionary.updateValue(weiboname! as AnyObject, forKey: kUserWeibonameKey)
        }
        if email != nil {
            dictionary.updateValue(email! as AnyObject, forKey: kUserEmailKey)
        }
        if regtime != nil {
            dictionary.updateValue(regtime! as AnyObject, forKey: kUserRegtimeKey)
        }
        if useraddress != nil {
            dictionary.updateValue(useraddress! as AnyObject, forKey: kUserUseraddressKey)
        }
        if username != nil {
            dictionary.updateValue(username! as AnyObject, forKey: kUserUsernameKey)
        }
        if birthday != nil {
            dictionary.updateValue(birthday! as AnyObject, forKey: kUserBirthdayKey)
        }
        if nation != nil {
            dictionary.updateValue(nation! as AnyObject, forKey: kUserNationKey)
        }
        if thrid != nil {
            dictionary.updateValue(thrid! as AnyObject, forKey: kUserThridKey)
        }
        if sex != nil {
            dictionary.updateValue(sex! as AnyObject, forKey: kUserSexKey)
        }
        
        return dictionary
    }
    
    
}
